package com.itany.controller;


import com.itany.exception.UsernameAndPasswordErrorException;
import com.itany.pojo.ManagerUser;
import com.itany.service.ManagerUserService;
import com.itany.vo.ActionResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class ManagerUserController {

        @Autowired
        private ManagerUserService userService;


        @RequestMapping("/login")
        @ResponseBody
        public ActionResult login(ManagerUser managerUser, HttpSession session){
                ActionResult result=new ActionResult();

                try {
                        ManagerUser login = userService.login(managerUser);


                        System.out.println("login.getUsername()"+login.getUsername());
                        System.out.println("login.getUsername()"+login.getPassword());
                        session.setAttribute("user",login);
                        result.setSuccess(true);
                } catch (UsernameAndPasswordErrorException e) {
                        result.setSuccess(false);
                        result.setMsg(e.getMessage());
                        e.printStackTrace();
                }
                return result;

        }
}
